<template>
  <div class="article">
    <el-card>
      <template #header>
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>内容管理</el-breadcrumb-item>
        </el-breadcrumb>
      </template>
      <el-form label-width="100px">
        <el-form-item label="状态">
          <el-radio-group v-model="form.status">
            <el-radio :label="null">全部</el-radio>
            <el-radio :label="0">草稿</el-radio>
            <el-radio :label="1">待审核</el-radio>
            <el-radio :label="2">审核通过</el-radio>
            <el-radio :label="3">审核失败</el-radio>
            <el-radio :label="4">已删除</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="频道">
          <el-select v-model="form.channel_id" filterable placeholder="请选择">
            <el-option
              v-for="item in channelslist"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="日期">
          <el-date-picker
            v-model="form.picker"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="">
          <el-button type="primary" @click="submit">筛选</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card>
      <template #header> 根据赛选条件共查询到{{ total }}条数据 </template>
      <el-table :data="list">
        <el-table-column label="封面">
          <template v-slot="scope">
            <img class="cover" :src="scope.row.cover.images[0]" alt="" />
          </template>
        </el-table-column>
        <el-table-column label="标题" prop="title"></el-table-column>
        <el-table-column label="状态" prop="status"></el-table-column>
        <el-table-column label="发布时间" prop="pubdate"></el-table-column>
        <el-table-column label="阅读数" prop="read_count"></el-table-column>
        <el-table-column label="评论数" prop="comment_count"></el-table-column>
        <el-table-column label="点赞数" prop="like_count"></el-table-column>
        <el-table-column label="操作">
          <template v-slot="scope">
            <div>
              <el-button type="primary" icon="el-icon-edit" circle></el-button>
              <el-button
                @click="list.splice(scope.store.$index, 1)"
                type="danger"
                icon="el-icon-delete"
                circle
              ></el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { channels, mpArticles } from '@/api/index.js'
export default {
  data () {
    return {
      form: {
        picker: [],
        status: null,
        channel_id: '',
        begin_pubde: '',
        end_pubdat: '',
        page: 1,
        per_page: 10
      },
      channelslist: [],
      list: [],
      total: 0
    }
  },
  methods: {
    async submit () {
      const res = await mpArticles(this.form)
      this.list = res.data.results
      this.total = res.data.total_count
      // console.log(res)
    },
    look (scope) {
      console.log(scope)
      console.log(this.list)
    }
  },
  watch: {
    'form.picker': {
      handler (newVal, oldVal) {
        if (newVal.length === 2) {
          this.form.begin_pubde = newVal[0]
          this.form.end_pubdat = newVal[1]
        }
      },
      deep: true
    }
  },
  async created () {
    const res = await channels()
    this.channelslist = res.data.channels
    // console.log(res)
    await this.submit()
  }
}
</script>

<style lang="less" scoped>
.cover {
  width: 50px;
}
</style>
